<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$setting=$this->plugin_setting('setting');
set_html('title','我的二维码');
$myshop=pdo_get('jy_levelfee_shop',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
if(!$myshop['mid']){
	exi('您还没有小店！前往创建！','error','jy_levelfee/set/main/');
}
if($_RQ['op']=='main'){
	if($setting['closed_qrcode']){
		exi('没有开启推广二维码','error','/index/');
	}
	$jy_poster = $this->plugin_exists('jy_poster');
	if($jy_poster){
		$poster=pdo_get('jy_poster_poster',array('isdefault'=>1,'type'=>4,'uniacid'=>$_SESSION['uniacid']));
		if($poster['id']){
			exi('','','jy_poster/build//posterid='.$poster['id']);
		}
	}
	$setting['tcommission']=$setting['tcommission']?$setting['tcommission']:'佣金';
	if($setting['become_child']==1){
		$setting['t1']='如果您的好友下单，';
	}else{
		$setting['t1']='如果您的好友下单并付款，';
	}
	$setting['torder']=$setting['torder']?$setting['torder']:'分销订单';
	$setting['tmydown']=$setting['tmydown']?$setting['tmydown']:'我的下线';
	$setting['twithdraw']=$setting['twithdraw']?$setting['twithdraw']:'提现';	
	$return['setting']=$setting;
	$url=custom_url('jy_levelfee/myshop/main/mid='.$_SESSION['uid'].'&fromuser='.$_SESSION['uid'],true);
	$return['qrcode']=cfc('tools')->createqrcode($url,'250',true);
	$return['qrcode']=tomedia($return['qrcode']);
	$image=ROOT_AT.'images/jy_levelfee/'.$_SESSION['uniacid'].'/id'.$_SESSION['uid'].'.jpg';
	if(!file_exists($image)){
		$url='/jy_levelfee/myshop/index?mid='.$_SESSION['uid'].'&fromuser='.$_SESSION['uid'];
		$wxapp=pdo_get('core_account_wxapp',array('id'=>$_SESSION['wxapp_id'],'uniacid'=>$_SESSION['uniacid']));
		if($_SESSION['fromh5wxapp']){
			$url='/jy_levelfee/myshop//&mid='.$_SESSION['uid'].'&fromuser='.$_SESSION['uid'];
			$url='/pages/index/index?url='.urlencode($url);
		}
		$res=model('core/wxapp')->appcode($url,$wxapp['appid'],$wxapp['appsecret'],200);
		$path=ROOT_AT.'images/jy_levelfee/'.$_SESSION['uniacid'];
		if(!file_exists($path)){
				mkdir($path,0700, true);
		}
		file_put_contents($path.'/id'.$_SESSION['uid'].'.jpg',$res);
	}
	$return['appcode'] = 'images/jy_levelfee/'.$_SESSION['uniacid'].'/id'.$_SESSION['uid'].'.jpg';
	if($_SESSION['fromh5wxapp'] || $_SESSION['os']=='wxapp'){
		$return['qrcode']=$return['appcode'];
	}
	$return['sharedata']=array(
			'title'=>$myshop['title']?$myshop['title']:'我的小店',
			'desc'=>$myshop['desc']?:$myshop['title'].'，欢迎光临，我的小店！！',
			'link'=>custom_url('jy_levelfee/myshop/main/mid='.$_SESSION['uid'],true),
			'imgUrl'=>tomedia($myshop['logo']),
	);
	exi($return);
}

?>